package com.huishu.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huishu.commons.pojo.BasePage;
import com.huishu.commons.pojo.Result;
import com.huishu.user.pojo.model.MemberStyleDO;
import com.huishu.user.service.MemberStyleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author generator@ljj
 * @since 2023-06-28
 */
@RestController
@RequestMapping("/member-style")
public class MemberStyleController {

    @Autowired
    private MemberStyleService memberStyleService;

    @PostMapping("/createOrUpdate")
    public Result createOrUpdate(@RequestBody MemberStyleDO memberStyleDO) {
        return memberStyleService.saveOrUpdate(memberStyleDO) ? Result.success() : Result.fail();
    }

    @PostMapping("/pageList")
    public Result pageList(@RequestBody BasePage basePage) {
        return memberStyleService.pageList(basePage);
    }

    @PostMapping("/openOrClose")
    public Result openOrClose(@RequestBody MemberStyleDO memberStyleDO) {
        return memberStyleService.openOrClose(memberStyleDO);
    }

    @GetMapping("/get-member-style")
    public Result getMemberStyle() {
        LambdaQueryWrapper<MemberStyleDO> queryWrapper = Wrappers.lambdaQuery(MemberStyleDO.class)
                .eq(MemberStyleDO::getIsOpen, true);
        MemberStyleDO one = memberStyleService.getOne(queryWrapper);
        return Result.success(one);
    }
}
